package com.helloandroid.activitys

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.helloandroid.R
import com.helloandroid.ads.NativeAdUtil
import com.helloandroid.app.model.AppCache
import com.helloandroid.base.BaseActivity
import com.helloandroid.tools.MyTimeUtils
import com.helloandroid.vo.TxInfo
import com.helloandroid.vo.TxItem

class ViewHodler(private val rootView: View,
                 val tvTime:TextView,
                 val tvMoney:TextView
):RecyclerView.ViewHolder(rootView)

class RecordAdapter(val lst:List<TxItem>): RecyclerView.Adapter<ViewHodler>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHodler {
        val rootView = LayoutInflater.from(parent.context).inflate(R.layout.item_tx_record,parent,false)
        return ViewHodler(rootView,
                rootView.findViewById(R.id.tvTime),
                rootView.findViewById(R.id.tvMoney)
        )
    }

    override fun onBindViewHolder(holder: ViewHodler, position: Int) {
        val item = lst[position]
        holder.tvTime.text = "提现时间 ${MyTimeUtils.customString("yyyy-MM-dd HH:mm",item.timeStamp)}"
        holder.tvMoney.text = "${item.amount/100f}元"
    }

    override fun getItemCount(): Int {
        return lst.size
    }
}


class TXRecordActivity : BaseActivity() {

    lateinit var rvView:RecyclerView
    lateinit var tvEmpty:TextView
    var adapter:RecordAdapter? = null

//    var isReady = false
//    val model:TXRecordViewModel by viewModels()

    var txInfo :TxInfo? = null


    override fun getContentViewResId() = R.layout.activity_txrecord

    override fun initView() {
        rvView = findViewById(R.id.rvView)
        tvEmpty = findViewById(R.id.tvEmpty)
        findBtn(R.id.ibBack).setOnClickListener {
            finish()
        }

        txInfo = AppCache.copyTxInfo()
        if (txInfo == null || txInfo!!.arr.size < 1){
            rvView.visibility = View.GONE
            tvEmpty.visibility = View.VISIBLE
        }else{
            rvView.visibility = View.VISIBLE
            tvEmpty.visibility = View.GONE
            adapter = RecordAdapter(txInfo!!.arr)
            rvView.adapter = adapter
        }

        NativeAdUtil.showNativeAd(this,findViewById(R.id.nativeView))
    }

    override fun initData() {
//        model.getRecords {
//            isReady = true
//            adapter.notifyDataSetChanged()
//        }
    }
}